package sort;

import org.junit.Test;

public class SelectSort {
	@Test
	public void fun() {
		int[] list = {0, 1, 2, 3, 1, 4, 2};
		selectSort(list);
		for(int i : list) {
			System.out.print(i + "\t");
		}
	}
	public void selectSort(int[] list) {
		int min; //记录最小下标
		for(int i = 0; i < list.length - 1; i ++) {
			min = i;
			for(int j = i + 1; j < list.length; j ++) {
				if(list[j] < list[min]) {
					min = j;
				}
			}
			swap(i, min, list);
		}
	}
	public void swap(int i, int j, int[]list) {
		int temp = list[i];
		list[i] = list[j];
		list[j] = temp;
	}
}
